package com.lpf.nio;

import java.nio.IntBuffer;
import java.security.SecureRandom;

/**
 * 功能描述：展示IntBuffer各个方法的使用
 *
 * @author lpf
 * @date 2019/11/24 21:27
 * @version: 1.0
 **/
public class NioTest01_01 {

    public static void main(String arg[]) {

        IntBuffer buffer = IntBuffer.allocate(10);

        for (int i = 0; i < 5; i++) {
            int randomNumber = new SecureRandom().nextInt(20);
            buffer.put(randomNumber);
        }

        System.out.println("before flip：" + buffer.limit());  //10
        buffer.flip();
        System.out.println("after flip：" + buffer.limit()); //5

        while (buffer.hasRemaining()) {
            System.out.print("capacity:" + buffer.capacity()); //10
            System.out.print(" limit:" + buffer.limit()); //5
            System.out.print(" position:" + buffer.position()); //0 1 2 3 4
            System.out.println(" get:" + buffer.get());
        }
    }
}
